import type {
  ActionConfig,
  DataRecord,
  FormConfig,
  PageConfig,
  PaginationConfig,
  SearchFieldConfig,
  TableColumn,
} from './config.type'

/**
 * 完整的页面配置
 */
const config = {
  // 页面基本信息
  page: {
    title: '角色管理',
    description: '管理系统中的角色信息',
    permission: 'acl:role',
    targetNameField: 'name',
  } as PageConfig,

  // API接口配置
  api: {
    GET_URL: '/roles/list',
    CREATE_URL: '/roles',
    UPDATE_URL: '/roles',
    DELETE_URL: '/roles',
    BATCH_DELETE_URL: '/roles/batch-delete',
    GET_ROLE_PERMISSION_URL: '/roles/permissions',
    ASSIGN_PERMISSION_URL: '/roles/assign-permission',
  },

  // 搜索配置
  search: {
    fields: [
      {
        prop: 'name',
        label: '角色名称',
        type: 'input',
        placeholder: '按角色名称搜索',
        clearable: true,
      },
    ] as SearchFieldConfig[],
    showReset: true,
    searchButtonText: '搜索',
    resetButtonText: '重置',
  },

  // 表格列配置
  tableColumns: [
    {
      type: 'selection',
      label: '选择',
      width: 55,
      align: 'center',
    },
    {
      type: 'index',
      label: 'ID',
      width: 80,
      align: 'center',
    },
    {
      prop: 'name',
      label: '角色名称',
      minWidth: 'auto',
      align: 'center',
      showOverflowTooltip: true,
    },
    {
      prop: 'createdAt',
      label: '创建时间',
      type: 'date',
      width: 180,
      align: 'center',
      sortable: true,
      showOverflowTooltip: true,
      dateConfig: {
        format: 'YYYY-MM-DD',
      },
    },
    {
      prop: 'updatedAt',
      label: '更新时间',
      type: 'date',
      width: 180,
      align: 'center',
      sortable: true,
      showOverflowTooltip: true,
      dateConfig: {
        format: 'YYYY-MM-DD',
      },
    },
    {
      prop: 'description',
      label: '备注',
      minWidth: 120,
      align: 'center',
      showOverflowTooltip: true,
    },
    //  操作列在page.vue中统一配置
  ] as TableColumn<DataRecord>[],

  // 表单配置
  form: {
    fields: [
      {
        prop: 'name',
        label: '角色名称',
        type: 'input',
        placeholder: '请输入角色名称：如：管理员',
        required: true,
        maxlength: 50,
        showWordLimit: true,
      },
      {
        prop: 'code',
        label: '角色编码',
        type: 'input',
        placeholder: '请输入角色编码,如：admin',
        required: true,
        maxlength: 50,
        showWordLimit: true,
      },
      {
        prop: 'description',
        label: '备注',
        type: 'input',
        placeholder: '请输入备注信息',
        maxlength: 200,
        showWordLimit: true,
      },
      {
        prop: 'sort',
        label: '排列顺序',
        type: 'number',
        placeholder: '请输入排序值',
        min: 0,
        max: 999,
        value: 1,
      },
    ],
    rules: {
      name: [
        { required: true, message: '请输入角色名称', trigger: 'blur' },
        { min: 2, max: 50, message: '角色名称长度在 2 到 50 个字符', trigger: 'blur' },
      ],
      code: [
        { required: true, message: '请输入角色编码', trigger: 'blur' },
        { min: 2, max: 50, message: '角色编码长度在 2 到 50 个字符', trigger: 'blur' },
      ]
    },
    labelWidth: '100px',
    dialogWidth: '600px',
    addTitle: '新增角色',
    editTitle: '编辑角色',
  } as FormConfig,

  // 操作按钮配置
  actions: {
    add: {
      text: '新增角色',
      icon: 'Plus',
      permission: 'btn.Role.add',
    },
    batchDelete: {
      text: '批量删除',
      icon: 'Delete',
      permission: 'btn.Role.remove',
    },
  } as ActionConfig,

  // 分页配置
  pagination: {
    pageSizes: [5, 10, 20, 50, 100],
    defaultPageSize: 10,
  } as PaginationConfig,

  // 消息配置
  messages: {
    loadSuccess: '角色获取成功',
    loadError: '角色获取失败',
    addSuccess: '角色添加成功！',
    addError: '角色添加失败',
    editSuccess: '角色修改成功！',
    editError: '角色修改失败',
    deleteSuccess: '删除成功',
    deleteError: '删除失败',
    batchDeleteSuccess: '批量删除成功',
    batchDeleteError: '批量删除失败',
    selectDeleteItems: '请选择要删除的数据',
    deleteConfirm: '确定要删除这个角色吗？删除后无法恢复！',
    batchDeleteConfirm: '确定要删除选中的 {count} 个角色吗？删除后无法恢复！',
  },
}

export default config
